//
//  UserDefaults+Extension.swift
//  Sparrow
//  Created by Joey on 20/11/2017.
//

import Foundation

public struct Storage {
    
    public static func save(key: String, value: Any?) {
        guard let value = value else {
            UserDefaults.standard.setValue(nil, forKey: key)
            return
        }
        UserDefaults.standard.setValue(value, forKey: key)
        UserDefaults.standard.synchronize()
    }
    
    public static func load(key: String) -> Any? {
        return UserDefaults.standard.value(forKey:key)
    }
    
    public static func remove(key: String) {
        UserDefaults.standard.removeObject(forKey: key)
    }
}


extension Storage {
    
    public struct Name : Hashable, Equatable, RawRepresentable {
        
        public var rawValue: String
        
        public init(rawValue: String) {
            self.rawValue = rawValue
        }
    }
}

extension Storage.Name {
    
    public static let searchHistory = Storage.Name(rawValue: "搜索历史记录")
 
}
